<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/vds.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/main.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/goods.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/umeditor/themes/default/css/umeditor.min.css" />
<script type="text/javascript" src="public/theme/backend/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="public/theme/backend/js/vds.js"></script>
<script type="text/javascript" src="public/theme/backend/js/goods.js"></script>
<script type="text/javascript">
$(function(){
  $('#tabs').vdsTabsSwitch();
  UM.getEditor('goods_brief', {textarea:'goods_brief', toolbar:['source | fontfamily fontsize forecolor bold link unlink | removeformat']});
  UM.getEditor('goods_content', {textarea:'goods_content', imageUrl: "<{url m=$MOD c='goods' a='editor'}>", initialFrameWidth: '98%'});
});

function submitForm(){
  $('#goods_name').vdsChecker({required:true, maxlength:180});
  $('#goods_sn').vdsChecker({maxlength:20});
  $('#now_price').vdsChecker({required:true, decimal:true});
  $('#original_price').vdsChecker({decimal:true});
  $('#goods_weight').vdsChecker({decimal:true});
  $('#goods-form').vdsSubmit(true);
}
</script>
</head>
<body>
<{if $_GET['a'] == 'add'}>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>添加新商品</h2></div>
  <form method="post" enctype="multipart/form-data" action="<{url m=$MOD c='goods' a='add' step='submit'}>" id="goods-form">
    <div class="box">
      <div class="tabs mt5">
        <ul id="tabs">
          <li class="cur">基本信息</li>
          <li>商品图片</li>
          <li>商品详情</li>
          <li>购买选项</li>
          <li>其他信息</li>
        </ul>
      </div>
      <!-- 基本信息开始 -->
      <div class="module swcon mt5">
        <table class="dataform">
          <tr>
            <th width="110">商品名称</th>
            <td><input title="商品名称" class="w400 txt" name="goods_name" id="goods_name" type="text" /></td>
          </tr>
          <tr>
            <th>商品分类</th>
            <td>
              <select id="cate_id" name="cate_id" class="slt">
                <option value="0">无分类</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $cate_select as $v}>
                <option value="<{$v.cate_id}>"><{str_repeat('|— ',$v.lv)}> <{$v.cate_name}></option>
                <{/foreach}>
              </select>
            </td>
          </tr>
          <tr>
            <th>所属品牌</th>
            <td>
              <select id="brand_id" name="brand_id" class="slt">
                <option value="0">无品牌</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $brand_select as $v}>
                <option value="<{$v.brand_id}>"><{$v.brand_name}></option>
                <{/foreach}>
              </select>
            </td>
          </tr>
          <tr>
            <th>商品货号</th>
            <td><input title="商品货号" class="w200 txt" name="goods_sn" type="text" /><p class="c999 mt10">长度不应超过20个字符, 留空则系统会按约定规则自动生成货号</p></td>
          </tr>
          <tr>
            <th>当前售价</th>
            <td><input title="当前售价" class="w200 txt" name="now_price" id="now_price" type="text" /><p class="c999 mt10">售价请按此格式填写, 如: "188.00" 或 "8.00"</p></td>
          </tr>
          <tr>
            <th>原售价</th>
            <td>
              <input title="原售价" class="w200 txt" name="original_price" id="original_price" type="text" />
              <p class="c999 mt10">留空或为0时，前台不显示原售价</p>
	    </td>
          </tr>
          <tr>
            <th>商品简介</th>
            <td><script type="text/plain" id="goods_brief" style="width:100%;height:100px;"></script></td>
          </tr>
          <tr>
            <th>标记</th>
            <td>
              <div class="pad5">
                <label><input name="newarrival" type="checkbox" value="1" /><font class="c666 ml5">新品</font></label>
                <label class="ml20"><input name="recommend" type="checkbox" value="1" /><font class="c666 ml5">推荐</font></label>
                <label class="ml20"><input name="bargain" type="checkbox" value="1" /><font class="c666 ml5">特价</font></label>
              </div>
            </td>
          </tr>
          <tr>
            <th>状态</th>
            <td>
              <div class="pad5">
                <label><input type="radio" name="status" value="1" checked="checked" /><font class="green ml5">上架</font></label>
                <label class="ml20"><input type="radio" name="status" value="0" /><font class="red ml5">下架</font></label>
                <p class="c999 mt10">如状态选择下架，前台则不会显示该商品</p>
              </div>
            </td>
          </tr>
        </table>
      </div>
      <!-- 基本信息结束 -->
      <!-- 商品图片开始 -->
      <div class="module swcon mt5 hide">
        <table class="dataform">
          <tr>
            <th width="110">主要图片</th>
            <td><label><font class="c666 mr5">上传图片:</font><input name="goods_image" type="file" /></label><p class="c999 mt10">仅允许上传 "png"、"jpg"、"jpeg"、"gif" 类型的图片</p></td>
          </tr>
          <tr>
            <th>相册图片</th>
            <td>
              <button class="cbtn sm btn ml5" type="button" onclick="addAlbum()">+1 相册图片</button>
              <p class="c999 mt10">仅允许上传 "png"、"jpg"、"jpeg"、"gif" 类型的图片, 单张图片大小不能超过2M</p>
              <div class="mt5" id="album"></div>
            </td>
          </tr>
        </table>
      </div>
      <!-- 商品图片结束 -->
      <!-- 规格属性开始 -->
      <div class="module swcon mt5 hide"><script type="text/plain" id="goods_content" style="height:300px;"></script></div>
      <!-- 商品详细结束 -->
      <!-- 商品选项开始 -->
      <div class="module swcon mt5 hide">
        <table class="dataform">
          <tr>
            <th width="90">选项类型</th>
            <td>
              <select class="slt" id="opt-type">
                <option value="0">选择选项类型</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $opt_type_select as $k => $v}>
                <option value="<{$k}>"><{$v}></option>
                <{/foreach}>
              </select>
              <button type="button" class="cbtn btn" onclick="selectedOptType(this)">确定</button>
              <a class="blue ml10" href="<{url m=$MOD c='goods_optional_type' a='add'}>">新增选项类型</a>
            </td>
          </tr>
          <tr>
            <td colspan="2" id="opt-container"></td>
          </tr>
        </table>
      </div>
      <!-- 商品选项结束 -->
      <!-- 其他信息开始 -->
      <div class="module swcon mt5 hide">
        <table class="dataform">
          <tr>
            <th width="110">库存数量</th>
            <td><input title="库存数量" value="9999" class="w100 txt" name="stock_qty" id="stock_qty" type="text" /></td>
          </tr>
          <tr>
            <th>重量</th>
            <td><input title="重量" class="w100 txt" name="goods_weight" id="goods_weight" value="0.00" type="text" /><font class="c999 ml5">Kg (千克)</font></td>
          </tr>
          <tr>
            <th>Meta 关键词</th>
            <td>
              <textarea class="txtarea" name="meta_keywords" cols="80" rows="4"></textarea>
              <p class="caaa mt10">多个关键词请用半角逗号隔开，如开启 MySql FULLTEXT 搜索，将会将此项作为索引进行检索</p>
            </td>
          </tr>
          <tr>
            <th>Meta 描述</th>
            <td><textarea class="txtarea" name="meta_description" cols="80" rows="4"></textarea></td>
          </tr>
        </table>
      </div>
      <!-- 其他信息结束 -->
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并提交</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{else}>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>编辑商品:<font class="ml5">[<{$rs.goods_id}>]</font></h2></div>
  <form method="post" enctype="multipart/form-data" action="<{url m=$MOD c='goods' a='edit' step='submit' id=$rs.goods_id}>" id="goods-form">
    <div class="box">
      <div class="tabs mt5">
        <ul id="tabs">
          <li class="cur">基本信息</li>
          <li>商品图片</li>
          <li>商品详情</li>
          <li>购买选项</li>
          <li>其他信息</li>
        </ul>
      </div>
      <!-- 基本信息开始 -->
      <div class="module swcon mt10">
        <table class="dataform">
          <tr>
            <th width="110">商品名称</th>
            <td><input title="商品名称" class="w400 txt" name="goods_name" id="goods_name" type="text" value="<{$rs.goods_name}>" /></td>
          </tr>
          <tr>
            <th>商品分类</th>
            <td>
              <select id="cate_id" name="cate_id" class="slt">
                <option value="0">无分类</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $cate_select as $v}> <{if $v.cate_id == $rs.cate_id}>
                <option selected="selected" value="<{$v.cate_id}>"><{str_repeat('|— ',$v.lv)}> <{$v.cate_name}></option>
                <{else}>
                <option value="<{$v.cate_id}>"><{str_repeat('|— ',$v.lv)}> <{$v.cate_name}></option>
                <{/if}>
                <{/foreach}>
              </select>
            </td>
          </tr>
          <tr>
            <th>所属品牌</th>
            <td>
              <select id="brand_id" name="brand_id" class="slt">
                <option value="0">无品牌</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $brand_select as $v}> <{if $v.brand_id == $rs.brand_id}>
                <option selected="selected" value="<{$v.brand_id}>"><{$v.brand_name}></option>
                <{else}>
                <option value="<{$v.brand_id}>"><{$v.brand_name}></option>
                <{/if}> <{/foreach}>
              </select>
            </td>
          </tr>
          <tr>
            <th>商品货号</th>
            <td>
              <input title="商品货号" class="w200 txt" name="goods_sn" type="text" value="<{$rs.goods_sn}>" />
              <p class="c999 mt10">长度不应超过20个字符, 留空则系统会自动生成货号</p>
            </td>
          </tr>
          <tr>
            <th>当前售价</th>
            <td>
              <input title="当前售价" class="w200 txt" name="now_price" id="now_price" type="text" value="<{$rs.now_price}>" />
              <p class="c999 mt10">售价请按此格式填写, 如: "188.00" 或 "8.00"</p>
            </td>
          </tr>
          <tr>
            <th>原售价</th>
            <td>
	      <input title="原售价" class="w200 txt" name="original_price" id="original_price" type="text" value="<{$rs.original_price}>" />
	      <p class="c999 mt10">留空或为0时，前台不显示原售价</p>
	    </td>
          </tr>
          <tr>
            <th>商品简介</th>
            <td><script type="text/plain" id="goods_brief" style="width:100%;height:100px;"><{$rs.goods_brief nofilter}></script></td>
          </tr>
          <tr>
            <th>标记</th>
            <td>
              <div class="pad5">
                <label><input name="newarrival" type="checkbox" value="1" <{if $rs.newarrival == 1}>checked="checked"<{/if}> /><font class="c666 ml5">新品</font></label>
                <label class="ml20"><input name="recommend" type="checkbox" value="1" <{if $rs.recommend == 1}>checked="checked"<{/if}> /><font class="c666 ml5">推荐</font></label>
                <label class="ml20"><input name="bargain" type="checkbox" value="1" <{if $rs.bargain == 1}>checked="checked"<{/if}> /><font class="c666 ml5">特价</font></label>
              </div>
            </td>
          </tr>
          <tr>
            <th>状态</th>
            <td>
              <p> 
                <{if $rs.status == 1}>
                <label class="green mr10"><input type="radio" name="status" value="1" checked="checked" />上架</label>
                <label class="red"><input type="radio" name="status" value="0" />下架</label>
                <{else}>
                <label class="green mr10"><input type="radio" name="status" value="1" />上架</label>
                <label class="red"><input type="radio" name="status" value="0" checked="checked" />下架</label>
                <{/if}>
              </p>
              <p class="c999 mt10">如状态选择下架，前台则不会显示该商品</p></td>
          </tr>
          <tr>
            <th>创建时间</th>
            <td><p class="pad5 c888"><{date('Y-m-d h:i:s', $rs.created_date)}></p></td>
          </tr>
        </table>
      </div>
      <!-- 基本信息结束 -->
      <!-- 商品图片开始 -->
      <div class="module swcon mt10 hide">
        <table class="dataform">
          <tr>
            <th width="110">主要图片</th>
            <td>
              <p><label><font class="c666 mr5">上传新图片:</font><input name="goods_image" type="file" /></label></p>
              <{if !empty($rs.goods_image)}>
              <p class="mt10">
                <label class="c666">原图片路径:</label>
                <input class="w400 txt" type="text" value="upload/goods/image/<{$rs.goods_image}>" disabled="disabled" />
                <a title="查看图片" class="ml5" onclick="$(this).vdsPopMedia({src:'upload/goods/image/<{$rs.goods_image}>'})"><i class="icon picture "></i></a>
              </p>
              <{/if}>
              <p class="c999 mt10">仅允许上传 "png"、"jpg"、"jpeg"、"gif" 类型的图片, 单张图片大小不能超过2M</p>
            </td>
          </tr>
          <tr>
            <th>相册图片</th>
            <td>
              <div class="imgli module cut"> <{foreach $album_list as $v}>
                <dl>
                  <dd class="mt5"><img width="50" height="50" src="upload/goods/album/<{$v.image}>" /></dd>
                  <dd class="mt5"><a title="删除" class="blue" onclick="removeAlbumImg(this, <{$v.id}>)">[-]</a></dd>
                </dl>
                <{/foreach}>
                <input type="hidden" name="album_removed" id="album_removed" />
              </div>
              <p class="mt10"><button class="cbtn sm btn ml5" type="button" onclick="addAlbum()">+1 相册图片</button></p>
              <p class="c999 mt10">仅允许上传 "png"、"jpg"、"jpeg"、"gif" 类型的图片, 单张图片大小不能超过2M</p>
              <div class="mt5" id="album"></div>
            </td>
          </tr>
        </table>
      </div>
      <!-- 商品图片结束 -->
      <!-- 规格属性开始 -->
      <div class="module swcon mt10 hide"><script type="text/plain" id="goods_content" style="height:300px;"><{$rs.goods_content nofilter}></script></div>
      <!-- 商品详细结束 -->
      <!-- 商品选项开始 -->
      <div class="module swcon mt10 hide">
        <table class="dataform">
          <tr>
            <th width="90">选项类型</th>
            <td>
              <select class="slt" id="opt-type">
                <option value="0">选择选项类型</option>
                <option disabled="disabled">------------------------------</option>
                <{foreach $opt_type_select as $k => $v}>
                <option value="<{$k}>"><{$v}></option>
                <{/foreach}>
              </select>
              <button type="button" class="cbtn btn" onclick="selectedOptType(this)">确定</button>
              <a class="blue ml10" href="<{url m=$MOD c='goods_optional_type' a='add'}>">新增选项类型</a>
            </td>
          </tr>
          <tr>
            <td colspan="2" id="opt-container">
              <{if !empty($opt_list)}>
              <{foreach $opt_list as $v}>
              <dl class="optlsdl">
                <dt>
                  <font class="c888 mr10" data-id="<{$v.type_id}>"><{$v.type_name}></font>
                  <button type="button" class="add mbtn btn mr5" onclick="addOptVal(this)">+1 可选值</button>
                  <button type="button" class="del mbtn btn" onclick="removeOpt(this)">删除</button>
                  <p class="mt10 c999">左边输入选项内容, 右边输入增加价格(留空则价格不变)</p>
                </dt>
                <{foreach $v.children as $vv}>
                <dd>
                  <a class="f14 blue mr5" title="移除" onclick="removeOptVal(this)">[-]</a>
                  <input class="w150 txt" name="goods_opts[text][]" type="text" value="<{$vv.opt_text}>" />
                  <input class="w100 txt" name="goods_opts[price][]" type="text" value="<{$vv.opt_price}>" />
                  <input type="hidden" name="goods_opts[type][]" value="<{$v.type_id}>" />
                </dd>
                <{/foreach}>
              </dl>
              <{/foreach}>
              <{/if}>
            </td>
          </tr>
        </table>
      </div>
      <!-- 商品选项结束 -->
      <!-- 其他信息开始 -->
      <div class="module swcon mt10 hide">
        <table class="dataform">
          <tr>
            <th width="110">库存数量</th>
            <td><input title="库存数量" class="w100 txt" name="stock_qty" id="stock_qty" type="text" value="<{$rs.stock_qty}>" /></td>
          </tr>
          <tr>
            <th>重量</th>
            <td><input title="重量" class="w100 txt" name="goods_weight" id="goods_weight" type="text" value="<{$rs.goods_weight}>" /><font class="c999 ml5">Kg (千克)</font></td>
          </tr>
          <tr>
            <th>Meta 关键词</th>
            <td>
              <textarea class="txtarea" name="meta_keywords" cols="80" rows="4"><{$rs.meta_keywords}></textarea>
              <p class="caaa mt10">多个关键词请用半角逗号隔开，如开启 MySql FULLTEXT 搜索，将会将此项作为索引进行检索</p>
            </td>
          </tr>
          <tr>
            <th>Meta 描述</th>
            <td><textarea class="txtarea" name="meta_description" cols="80" rows="4"><{$rs.meta_description}></textarea></td>
          </tr>
        </table>
      </div>
      <!-- 其他信息结束 -->
      <div class="submitbtn">
        <button type="button" class="ubtn btn" onclick="submitForm()">保存并更新</button>
        <button type="reset" class="fbtn btn">重置表单</button>
      </div>
    </div>
  </form>
</div>
<{/if}>
<script type="text/template" id="add-album-tpl">
<div class="mrimgtr">
  <a class="blue mr5" title="移除">[-]</a>
  <label><font class="c666 mr5">上传图片:</font><input name="goods_album[]" type="file" /></label>
</div> 
</script>
<script type="text/template" id="opt-tpl">
<dl class="optlsdl">
  <dt>
    <font class="c888 mr10" data-id="{{type_id}}">{{type_name}}</font>
    <button type="button" class="add mbtn btn mr5" onclick="addOptVal(this)">+1 可选值</button>
    <button type="button" class="del mbtn btn" onclick="removeOpt(this)">删除</button>
    <p class="mt10 c999">左边输入选项内容, 右边输入增加价格(留空则价格不变)</p>
  </dt>
  <dd>
    <a class="f14 blue mr5" title="移除" onclick="removeOptVal(this)">[-]</a>
    <input class="w150 txt" name="goods_opts[text][]" type="text" />
    <input class="w100 txt" name="goods_opts[price][]" type="text" />
    <input type="hidden" value="{{type_id}}" name="goods_opts[type][]" />
  </dd>
</dl>
</script>
<script type="text/template" id="opt-val-tpl">
<dd>
  <a class="f14 blue mr5" title="移除" onclick="removeOptVal(this)">[-]</a>
  <input class="w150 txt" name="goods_opts[text][]" type="text" />
  <input class="w100 txt" name="goods_opts[price][]" type="text" />
  <input type="hidden" value="{{type_id}}" name="goods_opts[type][]" />
</dd>
</script>
<script type="text/javascript" src="public/theme/backend/umeditor/umeditor.config.js"></script>
<script type="text/javascript" src="public/theme/backend/umeditor/umeditor.min.js"></script>
</body>
</html>
